#!/bin/bash
#
# Don't execute this script directly, instead it is copied into the webtry
# user's directory and executed as the user webtry by the webtry_setup.sh
# script.
#
# See the README file for detailed installation instructions.
cd
pwd

# Install depot_tools.
if [ -d depot_tools ]; then
  (cd depot_tools && git pull);
else
  git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git;
fi
export PATH=$PATH:$HOME/depot_tools

# Install Go
if [ -d go ]; then
  echo Go already installed.
else
  wget https://go.googlecode.com/files/go1.2.1.linux-amd64.tar.gz
  tar -xzf go1.2.1.linux-amd64.tar.gz
fi
export GOROOT=$HOME/go
mkdir=$HOME/golib
export GOPATH=$HOME/golib

export PATH=$PATH:$GOROOT/bin

mkdir /home/webtry/cache
mkdir /home/webtry/inout
chmod 777 /home/webtry/inout

# Sometimes you need to test patches on the server, to do that uncomment
# the following commented out lines and update the PATCH env variable to the
# name of the codereview to use.

# rm -rf skia

# Checkout the skia code and dependencies.
mkdir skia
cd skia
gclient config --name . https://skia.googlesource.com/skia.git
gclient sync
git checkout master

# PATCH=issue196723021_100001.diff
# rm $PATCH
# wget https://codereview.chromium.org/download/$PATCH
# git apply $PATCH

GYP_GENERATORS=ninja ./gyp_skia gyp/webtry.gyp gyp/most.gyp -Dskia_gpu=0
ninja -C out/Debug webtry

cd experimental/webtry

go get -d
go build webtry.go
